package vip.ifmm.lehouse.api.gateway.controller.commodity;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.ifmm.lehouse.api.gateway.annotation.FromSession;
import vip.ifmm.lehouse.commodity.service.api.CommodityCommentService;
import vip.ifmm.lehouse.common.bo.SessionBo;
import vip.ifmm.lehouse.common.dto.ServerResponse;
import vip.ifmm.lehouse.common.model.Comment;

/**
 * @author Red
 * email: 1318944013@qq.com
 * date: 2019/6/21 21:44
 */
@RestController
@RequestMapping("/commodity")
@Slf4j
public class CommodityCommentController {

    // 引用远程服务
    @Reference(owner = "red")
    private CommodityCommentService commentService;

    @PostMapping("/comment")
    public ServerResponse addComment(Comment comment, @FromSession SessionBo sessionBo) {
        return commentService.addComment(comment, sessionBo);
    }

    @DeleteMapping("/comment/{commodityId}/{commentId}")
    public ServerResponse deleteComment(@PathVariable("commodityId") Integer commodityId,
                                        @PathVariable("commentId") Integer commentId) {
        return commentService.deleteComment(commodityId, commentId);
    }

    @GetMapping("/comment/{commodityId}")
    public ServerResponse listComment(@PathVariable("commodityId") Integer commodityId,
                                      @RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
                                      @RequestParam(value = "pageNum", defaultValue = "8")Integer pageSize) {
        return commentService.listComment(commodityId, pageNum, pageSize);
    }

    @PostMapping("/comment/star")
    public ServerResponse starComment(Integer commentId) {
        return commentService.updateStar(commentId);
    }

}
